﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Locator.Stores;
using DataAccess.BusinessEntities;
using DataAccess;
using Locator.GeoLocation.Services;
using System.ServiceModel.Activation;
using System.Threading;
using System.Web;

namespace Locator.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class StoresService : IStoresService
    {
        public IStoresController StoresController { get; set; }

        /// <summary>
        /// Initializes a new instance of the StoresService class.
        /// </summary>
        public StoresService()
        {
            this.StoresController = new StoresController(new GeoLocationServiceAgent(), new SqlUnitOfWork());
            Thread.CurrentPrincipal = HttpContext.Current.User;
        }

        public List<PersonalLocation> GetPersonalLocationsForCurrentUser()
        {
            return this.StoresController.GetPersonalLocationsForCurrentUser();
        }

        public List<Store> FindStoresByPostalCode(string postalCode, int radiusInKm)
        {
            return this.StoresController.FindStoresByPostalCode(postalCode, radiusInKm);
        }

        public List<Store> FindStoresByLatitudeAndLongitude(decimal latitude, decimal longitude, int radiusInKm)
        {
            return this.StoresController.FindStoresByLatitudeAndLongitude(latitude, longitude, radiusInKm);
        }

        public List<Store> FindStoresByPersonalLocation(int personalLocationId, int radiusInKm)
        {
            return this.StoresController.FindStoresByPersonalLocation(personalLocationId, radiusInKm);
        }

        public List<Store> GetStoresForCurrentUser()
        {
            return this.StoresController.GetStoresForCurrentUser();
        }

        public List<Store> FindStoresNotUsedByCurrentUser()
        {
            return this.StoresController.FindStoresNotUsedByCurrentUser();
        }

        public List<string> AllCities()
        {
            return this.StoresController.AllCities();
        }

        public List<Store> FindStoresInCity(string cityName)
        {
            return this.StoresController.FindStoresInCity(cityName);
        }

        public void AddStoreForCurrentUser(int storeNumber)
        {
            this.StoresController.AddStoreForCurrentUser(storeNumber);
        }

        public void DeleteStoreForCurrentUser(int storeNumber)
        {
            this.StoresController.DeleteStoreForCurrentUser(storeNumber);
        }
    }
}
